/*
 * XLIFF2RDFView.java
 */

package xliff2rdf;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.filechooser.*;
import javax.swing.SwingUtilities;


//

import net.sf.saxon.Configuration;
import net.sf.saxon.event.Receiver;
import net.sf.saxon.expr.instruct.TerminationException;
import net.sf.saxon.lib.FeatureKeys;
import net.sf.saxon.lib.TraceListener;
import net.sf.saxon.trace.AbstractTraceListener;
import net.sf.saxon.trace.ExpressionPresenter;
import net.sf.saxon.trace.TimedTraceListener;
import net.sf.saxon.trans.CommandLineOptions;
import net.sf.saxon.trans.CompilerInfo;
import net.sf.saxon.trans.LicenseException;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.DateTimeValue;
import net.sf.saxon.trans.CompilerInfo;
import net.sf.saxon.PreparedStylesheet;
import net.sf.saxon.Controller;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import javax.xml.transform.*;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import javax.swing.JFileChooser;


import java.net.*;
import java.io.*;

/**
 * The application's main frame.
 */
public class XLIFF2RDFView extends FrameView {
    
    private CompilerInfo compilerInfo;
    String sourceFileName = null;
    String outputFileName = null;
    File outputFile = null;

    protected Configuration config;
    protected boolean useURLs = false;
    protected boolean showTime = false;
    protected int repeat = 1;
    String sourceParserName = null;
    boolean schemaAware = false;



    public XLIFF2RDFView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                                  } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                                   }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = XLIFF2RDFApp.getApplication().getMainFrame();
            aboutBox = new XLIFF2RDFAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        XLIFF2RDFApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        checkbox1 = new java.awt.Checkbox();
        textField1 = new java.awt.TextField();
        popupMenu1 = new java.awt.PopupMenu();

        mainPanel.setName("mainPanel"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(xliff2rdf.XLIFF2RDFApp.class).getContext().getActionMap(XLIFF2RDFView.class, this);
        jButton2.setAction(actionMap.get("doTransform")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(xliff2rdf.XLIFF2RDFApp.class).getContext().getResourceMap(XLIFF2RDFView.class);
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        jButton3.setAction(actionMap.get("openfile")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N

        jButton5.setAction(actionMap.get("quit")); // NOI18N
        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N

        jButton4.setAction(actionMap.get("preview")); // NOI18N
        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setName("jButton4"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addGap(100, 100, 100)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(81, 81, 81))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap(103, Short.MAX_VALUE)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton5))
                .addGap(98, 98, 98))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        fileMenu.add(jMenuItem1);

        jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
        jMenuItem2.setName("jMenuItem2"); // NOI18N
        fileMenu.add(jMenuItem2);

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
        jMenu1.setName("jMenu1"); // NOI18N
        menuBar.add(jMenu1);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setText(resourceMap.getString("aboutMenuItem.text")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        checkbox1.setLabel(resourceMap.getString("checkbox1.label")); // NOI18N
        checkbox1.setName("checkbox1"); // NOI18N

        textField1.setName("textField1"); // NOI18N
        textField1.setText(resourceMap.getString("textField1.text")); // NOI18N

        popupMenu1.setLabel(resourceMap.getString("popupMenu1.label")); // NOI18N

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void openfile() {

        //File selector Java
        final JFileChooser fc = new JFileChooser();

        int returnVal = fc.showOpenDialog(XLIFF2RDFView.this.getComponent());

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            sourceFileName = file.getAbsolutePath();
            //This is where a real application would open the file.
            System.out.println("Opening: " + sourceFileName);
        } else {
            //
        }
    }

    /**
     * Create a new Controller. This method is protected so it can be overridden in a subclass, allowing additional
     * options to be set on the Controller
     * @param sheet The Templates object representing the compiled stylesheet
     * @param options The commmand line options
     * @param traceDestination destination for trace output
     * @return the newly constructed Controller to be used for the transformation
     * @throws TransformerException if any error occurs
     */

    protected Controller newController(
            Templates sheet, CommandLineOptions options, PrintStream traceDestination) throws TransformerException {
        Controller controller = (Controller)sheet.newTransformer();
        options.setParams(config, controller, null, null);
        controller.setTraceFunctionDestination(traceDestination);
        String initialMode = options.getOptionValue("im");
        if (initialMode != null) {
            controller.setInitialMode(initialMode);
        }
        String initialTemplate = options.getOptionValue("it");
        if (initialTemplate != null) {
            controller.setInitialTemplate(initialTemplate);
        }
        String now = options.getOptionValue("now");
        if (now != null) {
            DateTimeValue currentDateTime = (DateTimeValue)DateTimeValue.makeDateTimeValue(now, config.getConversionRules()).asAtomic();
            controller.setCurrentDateTime(currentDateTime);
        }
        return controller;
    }

    /**
     * Make an output file in the output directory, with filename extension derived from the
     * media-type produced by the stylesheet
     *
     * @param directory The directory in which the file is to be created
     * @param localName The local name of the file within the
     *                  directory, excluding the file type suffix
     * @param sheet     The Templates object identifying the stylesheet -
     *                  used to determine the output method, and hence the suffix to be
     *                  used for the filename
     * @return The newly created file
     */

    private File makeOutputFile(File directory, String localName, Templates sheet) {
        String mediaType = sheet.getOutputProperties().getProperty(OutputKeys.MEDIA_TYPE);
        String suffix = ".xml";
        if ("text/html".equals(mediaType)) {
            suffix = ".html";
        } else if ("text/plain".equals(mediaType)) {
            suffix = ".txt";
        }
        String prefix = localName;
        if (localName.endsWith(".xml") || localName.endsWith(".XML")) {
            prefix = localName.substring(0, localName.length() - 4);
        }
        return new File(directory, prefix + suffix);
    }

/**
     * Process a single source file using its associated stylesheet(s)
     *
     * @param sourceInput   Identifies the source file to be transformed
     * @param localName     The local name of the file within the
     *                      directory, excluding the file type suffix
     * @param outputFile    The output file to contain the results of the
     *                      transformation
     * @param options       Command line options
     * @param traceDestination Destination for trace output
     * @throws XPathException If the transformation fails
     */

    private void processFileAssoc(Source sourceInput, String localName, File outputFile,
                                 CommandLineOptions options, PrintStream traceDestination)
            throws TransformerException {

        Source style = PreparedStylesheet.getAssociatedStylesheet(config, sourceInput, null, null, null);
        Templates sheet = PreparedStylesheet.compile(style, config, compilerInfo);

        if (showTime) {
            System.err.println("Prepared associated stylesheet " + style.getSystemId());
        }

        Controller controller = newController(sheet, options, traceDestination);

        File outFile = outputFile;

        if (outFile != null && outFile.isDirectory()) {
            outFile = makeOutputFile(outFile, localName, sheet);
        }

        StreamResult result =
                (outFile == null ? new StreamResult(System.out) : new StreamResult(outFile.toURI().toString()));

        try {
            controller.transform(sourceInput, result);
        } catch (TerminationException err) {
            throw err;
        } catch (XPathException err) {
            // The error message will already have been displayed; don't do it twice
            if (!err.hasBeenReported()) {
                err.printStackTrace();
            }
            throw new XPathException("Run-time errors were reported");
        }


    }

     /**
     * Process a single file using a supplied stylesheet
     *
     * @param source        The source XML document to be transformed (maybe null if an initial template
     *                      is specified)
     * @param sheet         The Templates object identifying the stylesheet
     * @param outputFile    The output file to contain the results of the
     *                      transformation
     * @param options       The command line options
     * @param traceDestination Destination for output from fn:trace() function
     * @throws net.sf.saxon.trans.XPathException
     *          If the transformation fails
     */

    private void processFile(Source source, Templates sheet, File outputFile, CommandLineOptions options,
                            PrintStream traceDestination)
            throws TransformerException {


        int runs = 0;
        for (int r = 0; r < repeat; r++) {      // repeat is for internal testing/timing

            runs++;
            Controller controller = newController(sheet, options, traceDestination);

            Result result =
                    (outputFile == null ?
                    new StreamResult(System.out) :
                    new StreamResult(outputFile.toURI().toString()));

            try {
                controller.transform(source, result);
            } catch (TerminationException err) {
                throw err;
            } catch (XPathException err) {
                // The message will already have been displayed; don't do it twice
                if (!err.hasBeenReported()) {
                    err.printStackTrace();
                }
                throw new XPathException("Run-time errors were reported");
            }

        }
    }


    @Action
    public void doTransform() {
        
        String styleFileName = "C:\\Users\\Dimitra\\Desktop\\ACL_experiment\\1stcase\\XSLT1stcase.xsl";
        boolean useAssociatedStylesheet;
        boolean wholeDirectory = false;
        boolean precompiled;
        boolean dtdValidation = false;
        String styleParserName = null;
        boolean explain = false;
        String explainOutputFileName = null;
        String additionalSchemas = null;
        PrintStream traceDestination;
        TraceListener traceListener = null;
        boolean closeTraceDestination = false;


        Configuration config = null;
        CommandLineOptions options = new CommandLineOptions();
        boolean schemaAware = false;
        if (config == null && !schemaAware) {
            schemaAware = options.testIfSchemaAware();
        }


        if (config == null) {
            config = Configuration.newConfiguration();
            config.setVersionWarning(true);  // unless suppressed by command line options
            try {
                compilerInfo = config.getDefaultXsltCompilerInfo();
                if (schemaAware) {
                    if (!config.isLicensedFeature(Configuration.LicenseFeature.ENTERPRISE_XSLT)) {
                        throw new LicenseException("Configuration is not licensed for schema-aware XSLT processing",
                                LicenseException.WRONG_FEATURES);
                    }
                    compilerInfo.setSchemaAware(true);
                } else {
                    compilerInfo.setSchemaAware(false);
                }
            } catch (Exception err) {
                err.printStackTrace();
                quit(err.getMessage(), 2);
            }
        }

        // Process the named options

        try {

            // Apply those options which simply update the Configuration

            options.applyToConfiguration(config);

            // Apply options that are processed locally

            useAssociatedStylesheet = "on".equals(options.getOptionValue("a"));
            precompiled = options.getOptionValue("c") != null;

            

            //styleFileName = value;


            compilerInfo.setRecoveryPolicy(config.getRecoveryPolicy());

            // Check consistency of selected options


            List<String> positional = options.getPositionalOptions();
            int currentPositionalOption = 0;

            config.displayLicenseMessage();
            if (schemaAware && !config.isLicensedFeature(Configuration.LicenseFeature.ENTERPRISE_XSLT)) {
                if ("EE".equals(config.getEditionCode())) {
                    quit("Installed license does not allow schema-aware transformation", 2);
                } else {
                    quit("Schema-aware transformation requires Saxon Enterprise Edition", 2);
                }
            }


            List sources = null;
            if (sourceFileName != null) {
                boolean useSAXSource = dtdValidation; // sourceParserName != null || ;
                Object loaded = CommandLineOptions.loadDocuments(sourceFileName, false, config, useSAXSource);
                
                    wholeDirectory = false;
                    sources = new ArrayList(1);
                    sources.add(loaded);
                
            }

            outputFileName = sourceFileName;
            //todo: change *.xml in *.rdf
            outputFileName = outputFileName.substring(0, outputFileName.lastIndexOf('.'));
            outputFileName+=".rdf";
            System.out.println(outputFileName);


            traceDestination = config.getStandardErrorOutput();

            if (outputFileName != null && !wholeDirectory) {
                outputFile = new File(outputFileName);
                if (outputFile.isDirectory()) {
                    quit("Output is a directory, but input is not", 2);
                }
            }

            if (useAssociatedStylesheet) {
                
                    processFileAssoc((Source)sources.get(0), null, outputFile, options, traceDestination);
            } else {

                long startTime = (new Date()).getTime();

                PreparedStylesheet sheet = null;

                if (precompiled) {
                    try {
                        sheet = PreparedStylesheet.loadCompiledStylesheet(styleFileName, config);
                        if (showTime) {
                            long endTime = (new Date()).getTime();
                            System.err.println("Stylesheet loading time: " + (endTime - startTime) + " milliseconds");
                        }
                    } catch (Exception err) {
                        err.printStackTrace();
                    }
                } else {
                    Source styleSource;
                    XMLReader styleParser = null;
                    if (useURLs || styleFileName.startsWith("http:")
                            || styleFileName.startsWith("file:")) {
                        styleSource = config.getURIResolver().resolve(styleFileName, null);
                        if (styleSource == null) {
                            styleSource = config.getSystemURIResolver().resolve(styleFileName, null);
                        }
                    } else if (styleFileName.equals("-")) {
                        // take input from stdin
                        if (styleParserName == null) {
                            styleSource = new StreamSource(System.in);
                        } else if (Configuration.getPlatform().isJava()) {
                            styleParser = config.getStyleParser();
                            styleSource = new SAXSource(styleParser, new InputSource(System.in));
                        } else {
                            styleSource = new StreamSource(System.in);
                        }
                    } else {
                        File sheetFile = new File(styleFileName);
                        if (!sheetFile.exists()) {
                            quit("Stylesheet file " + sheetFile + " does not exist", 2);
                        }
                        if (styleParserName == null) {
                            styleSource = new StreamSource(sheetFile.toURI().toString());
                        } else {
                            InputSource eis = new InputSource(sheetFile.toURI().toString());
                            styleParser = config.getStyleParser();
                            styleSource = new SAXSource(styleParser, eis);
                        }
                    }

                    if (styleSource == null) {
                        quit("URIResolver for stylesheet file must return a Source", 2);
                    }
                    for (int j=0; j<repeat; j++) {
                        // Repeat loop is to get reliable performance data
                        sheet = PreparedStylesheet.compile(styleSource, config, compilerInfo);
                        if (styleParser != null) {
                            config.reuseStyleParser(styleParser);
                            // pointless, because the Configuration won't be used again; but we want to set a good example
                        }
                    }

                    
                }

                Source source = (sources == null ? null : (Source)sources.get(0));
                    processFile(source, sheet, outputFile, options, traceDestination);
                
            }
        } catch (TerminationException err) {
            quit(err.getMessage(), 1);
        } catch (TransformerConfigurationException err) {
            //err.printStackTrace();
            quit(err.getMessage(), 2);
        } catch (TransformerException err) {
            //err.printStackTrace();
            quit("Transformation failed: " + err.getMessage(), 2);
        } catch (TransformerFactoryConfigurationError err) {
            //err.printStackTrace();
            quit("Transformation failed: " + err.getMessage(), 2);
        } catch (LicenseException err) {
            quit("Transformation failed: " + err.getMessage(), 2);
        } catch (Exception err2) {
            err2.printStackTrace();
            quit("Fatal error during transformation: " + err2.getClass().getName() + ": " +
                    (err2.getMessage() == null ? " (no message)" : err2.getMessage()), 2);
        }

    }

   



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Checkbox checkbox1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private java.awt.PopupMenu popupMenu1;
    private java.awt.TextField textField1;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;

    private void quit(String message, int i) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Action
    public void preview() {
// Execute a command and get its process handle
      try {
          Process proc = Runtime.getRuntime().exec("C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe "+ outputFileName);
      } catch (IOException e)
      {

      }
    }

    }
